package cn.com.basic.framework.exception.exceptions;

import cn.com.basic.framework.exception.enums.IErrorCode;
import lombok.Data;

/**
 * dao层异常
 * @author mj1996
 */
@Data
public class DaoException extends RuntimeException{
    private final IErrorCode error;
    private final String msg;

    public DaoException(IErrorCode error) {
        super(String.format("Code:[%s],Desc:[%s]", error.getKey(), error.getValue()));
        this.error = error;
        this.msg = error.getValue();
    }
    public DaoException(IErrorCode error, String msg) {
        super(String.format("Code:[%s],Desc:[%s]", error.getKey(), error.getValue()));
        this.error = error;
        this.msg = msg;
    }

    public DaoException(IErrorCode error, Throwable e) {
        super(String.format("Code:[%s],Desc:[%s]", error.getKey(), error.getValue()));
        this.error = error;
        this.msg = e.getMessage();
    }


    public static DaoException newException(IErrorCode error) {
        return new DaoException(error);
    }

    public static DaoException newException(IErrorCode error, String msg) {
        return new DaoException(error, msg);
    }

    public static DaoException newException(IErrorCode error, Throwable e) {
        return new DaoException(error, e);
    }


}
